<?php

class Quad_Data_Ss extends Quad_Data_Abstract {
	
	public $number;
	public $matcher = '/^(\d{3})\D*(\d{2})\D*(\d{4})$/';
	
	public function __construct($no = '') {
		$this->raw = $no;
		$this->number = trim($no);
	}
	
	public static function create($no) {
		return new self($no);
	}
	
	public function isValid() {
		$matchesOk = preg_match($this->matcher, $this->number, $m);
		if (!$matchesOk) {
			return false;
		}
		// see http://www.socialsecurity.gov/history/ssn/geocard.html
		// and http://www.socialsecurity.gov/employer/stateweb.htm
		if ($m[1] == '000' || $m[2] == '00' || $m[3] == '0000') {
			return false;
		}
		// currently the highest area number (first 3 digits) is 733, but we allow higher
		return;
	}
	
	public function format($useDashes = true) {
		if (preg_match($this->matcher, $this->number, $m)) {
			$dash = ($useDashes ? '-' : '');
			return "{$m[1]}$dash{$m[2]}$dash{$m[3]}";
		}
		return $this->number;
	}
	
}